package com.fndsoft.zheshangmeap.net;

import android.os.Parcel;
import android.os.Parcelable;

import com.fndsoft.zheshangmeap.domain.ThreadMessage;

/**
 * @author carlos carlosk@163.com
 * @version 创建时间：2012-9-30 上午6:27:43 返回实体
 */

public class HttpReturnMessage implements Parcelable {
	private String resultContent;
	private Exception resultException;
	private boolean isSuccess;
	private ThreadMessage threadMessage;
	private byte[] resultByteArr;

	public HttpReturnMessage() {
		super();
		isSuccess = false;
	}

	public ThreadMessage getThreadMessage() {
		return threadMessage;
	}

	public void setThreadMessage(ThreadMessage threadMessage) {
		this.threadMessage = threadMessage;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(resultContent);
		if (null != resultException) {
			dest.writeException(resultException);
		}
		dest.writeInt(isSuccess ? 1 : 0);

	}

	public Parcelable.Creator<HttpReturnMessage> CREATOR = new Creator<HttpReturnMessage>() {

		@Override
		public HttpReturnMessage[] newArray(int size) {
			return new HttpReturnMessage[size];
		}

		@Override
		public HttpReturnMessage createFromParcel(Parcel source) {
			HttpReturnMessage httpReturnMessage = new HttpReturnMessage();
			httpReturnMessage.setResultContent(source.readString());
			try {
				source.readException();
			} catch (Exception e) {
				e.printStackTrace();
				httpReturnMessage.setResultException(e);
			}
			httpReturnMessage.setSuccess(source.readInt() == 1);
			return httpReturnMessage;
		}
	};

	public String getResultContent() {
		return resultContent;
	}

	public void setResultContent(String resultContent) {
		this.resultContent = resultContent;
	}

	public Exception getResultException() {
		return resultException;
	}

	public void setResultException(Exception resultException) {
		this.resultException = resultException;
	}

	public boolean isSuccess() {
		return isSuccess;
	}

	public void setSuccess(boolean isSuccess) {
		this.isSuccess = isSuccess;
	}
	
	public byte[] getResultByteArr() {
		return resultByteArr;
	}

	public void setResultByteArr(byte[] resultByteArr) {
		this.resultByteArr = resultByteArr;
	}

	@Override
	public String toString() {
		return "HttpReturnMessage [resultContent=" + resultContent
				+ ", resultException=" + resultException + ", isSuccess="
				+ isSuccess + "]";
	}

}
